package com.weitu.hiddenDanger.controller;

import com.weitu.base.controller.BaseController;
import com.weitu.hiddenDanger.entity.HiddenDangerInfo;
import com.weitu.hiddenDanger.service.HDAccountService;
import com.weitu.paging.DataGridPagination;
import com.weitu.plugin.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 隐患台账controller
 * Created by fanyuting on 2017/4/20 0020.
 */
@Controller
@RequestMapping("hiddenDanger/hdAccount")
public class HDAccountController extends BaseController {
    private static final String MODULE_BATH_PATH = BASE_JSP_PATH+"hiddenDanger/hdAccount/";
    @Autowired
    private HDAccountService hdAccountService;
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public String toHDAccountListPage(){
        return MODULE_BATH_PATH+"list";
    }
    /**
     * 查询分页列表数据
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/queryListByParam")
    public Object queryList(HttpServletRequest request){

        Map<String,Object> map = new HashMap<String,Object>();
        //获取前台参数
        putParametersIntoMap(map);
        Integer totalNum = hdAccountService.queryListCount(map);//获取总数
        DataGridPagination pagination = DataGridPagination.getInstance(request, totalNum);
        PageView pageView = pagination.getPageView();//生成pageView分页对象
        map.put("pageView", pageView);
        List<Map<String,Object>> list =  hdAccountService.queryList(map);
        return  pagination.flushDataGridData(list);
    }
}
